//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
import gridFooter from "./order/small_order_item.vue";
import gridHeader from './order/PlaceAnOrder'
import orderDetails from './order/orderDetails'
// import RecordManually from '../../views/order/V_RecordManually.vue'
let extension = {
    components: {//动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader:gridHeader,//{ template: "<div>扩展组xx件</div>" },
        gridBody: orderDetails,
        gridFooter: gridFooter,
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        // modelHeader: RecordManually,
        modelBody: '',
        modelFooter: ''
    },
    buttons: {view: [
      // {
      //   name: "手工录入",
      //   icon: 'md-add',
      //   value: 'SGLR',
      //   class: '',
      //   type: 'error',
      //   index: 1,//显示的位置
      //   onClick: function () {

      //        this.$refs.gridHeader.open2();
      //   }
      // },
    ], box:[],  detail:[
      // {
      // name: "取消商品",
      // icon: 'md-close',
      // value: '',
      // class: '',
      // type: 'error',
      // index: 0,//显示的位置
      // onClick: function () {
      //   console.log(this.$refs.detail.getSelected(),"this.$refs.detail.");

      // }}
    ]},//扩展的按钮
    methods: {//事件扩展
      getcolumns(field) {
        let option;
        this.columns.forEach(x => {
            if (x.field == field) {
              option = x;
            }
        });
        return option;
      },
       onInit() {
        this.$store.getters.data().viewPageTest=this;
        this.single=true;
        this.textInline=true;
        this.ck=false;
        this.columnIndex = true;
        this.maxBtnLength = 3;
        this.boxOptions.height = 530;
        this.boxOptions.width= 900;
        this.pagination.sortName = "createDate";  //设置排序字段
        let param = {
          order: "desc",
          page: 1,
          rows: 100,
          sort: "id",
          wheres: `[{\"name\":\"distributorCode\",\"value\":\''\",\"displayType\":\"text\"}]`
        };
  
        this.http
          .post("/api/Mall_distributor_source/GetSourcePageData", param)
          .then(res => {
            if (res.rows.length > 0) {
              let option=this.getcolumns('sourceid_distributor')
              option.bind.data = res.rows.map(i => {
                return {
                  key: i.id,
                  value: i.sourceName
                };
              });
            }
          });
       this.pagination.order = "desc" ; //排序方式desc或者asc
       //this.searchFormFields.is_pay = 3;
          this.$store.getters.data().order =this;
          this.columns.push({
            title: '操作',
            fixed: 'right',
            width: 200,
            render: (h, { row, column, index }) => {
                return h(
                    "div", { style: {} }, [
                        h(
                            "a", {
                                props: {},
                                style: {},
                                on: {
                                    click: (e) => {
                                      this.$refs.gridBody.open(row,this.$refs.gridFooter.$refs.tableList.dataList[0].goodcode);
                                    }
                                }
                            },
                            "订单详情"
                        ),
                      //   h(
                      //     "a", {
                      //         props: {},
                      //         style: {},
                      //         on: {
                      //             click: (e) => {
                      //               this.linkData(row);
                      //             }
                      //         }
                      //     },
                      //     "    编辑"
                      // ),
                    //   h(
                    //     "a", {
                    //         props: {},
                    //         style: {},
                    //         on: {
                    //             click: (e) => {
                    //               this.http.post("api/VSmallOrders/getReissue",{id:row.order_number}).then(reslut=>{

                    //               })
                    //               //this.linkData(row);
                    //             }
                    //         }
                    //     },
                    //     "    重新下发   "
                    // ),
                     h(
                      "a", {
                          props: {},
                          style: {},
                          on: {
                              click: (e) => {
                                this.$refs.gridHeader.open4(row);
                              }
                          }
                      },
                      "    操作订单"
                  ),
                  h(
                    "a", {
                        props: {},
                        style: {},
                        on: {
                            click: (e) => {
                              this.$refs.gridHeader.open8(row);
                            }
                        }
                    },
                    "    日志查看"
                ),
                    ])
            }
        })
       },
       onInited() {
        //this.height = this.height-300;
        this.detailOptions.height = this.detailOptions.height - 200;
      },
       order(){

        //this.$refs.gridHeader.reset();
       // this.searchAfter(rows);
       this.$refs.gridHeader.open1();
        },
        modelOpenAfter() {
          //获取当前弹出框是新建还是编辑状态
          let isEDIT = this.currentAction == this.const.EDIT;
        //  console.log(isEDIT);
          //点击弹出框后，如果是编辑状态，禁止编辑帐号，如果新建状态，将帐号字段设置为可编辑
          this.editFormOptions.forEach(item => {
              item.forEach(x => {
                      //如果是编辑帐号设置为只读
                      if (x.field == "order_number") {
                          //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                          this.$set(x, "disabled", true)
                      }
                      if (x.field == "ticketsCode") {
                          //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                          this.$set(x, "disabled", true)
                      }
                      if (x.field == "bookingName") {
                        //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                        this.$set(x, "disabled", true)
                    }
                      if (x.field == "type") {
                        //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                        this.$set(x, "disabled", true)
                    }
                      if (x.field == "status") {
                        //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                        this.$set(x, "disabled", true)
                    }
                    if (x.field == "bookingPhone") {
                      //disabled是editFormOptions的动态属性，这里只能通过this.$set修改值
                      this.$set(x, "disabled", true)
                  }
                  })
          })
      },
      rowClick({ row, column, event }) { //查询界面table点击行选中当前行
        //console.log(row,column,event);
        let where = {
                sort:"id",
                value:row.id
          //{"name":"refundStatus","value":2,displayType:"text"},
        //设置为like模糊查询
          };
        this.$refs.table.$refs.table.toggleRowSelection(row);
        this.$refs.gridFooter.$refs.tableList.load(where)
        if(this.$refs.table.getSelected().length>1){
          this.$refs.gridFooter.$refs.tableList.reset()
        }
        return true;
       },
       searchAfter(rows) {
        //页面加载或者刷新数据后直接显示第一行的明细
        //console.log(rows);
        if (rows.length) {
          let where = {
            sort:"id",
            value:rows[0].id
        };
          // this.$nextTick(() => {
          this.$refs.gridFooter.$refs.tableList.load(where)
          // })
         }else{
          //没有数据时，清空明细数据
          this.$refs.gridFooter.$refs.tableList.reset()
        }
        return true;
      },
      // loadInternalDetailTableBefore(param){
      //   console.log("查询数据前",param)
      //   param.wheres.push({"name":"order_id","value":param..va,displayType:"text"})
      //   console.log("查询数据前",param)
      // }
    }

};
export default extension;
